//
//  NProblemCellFrame.m
//  nncloud
//
//  Created by gdy on 2018/9/26.
//  Copyright © 2018年 youedata. All rights reserved.
//

#import "NProblemCellFrame.h"

@implementation NProblemCellFrame

- (void)setModel:(NProblemModel *)model
{
    
    _model = model;
    if ([model.cellType isEqualToString:ProblemCellTypeTTitle]) {

        _cellHeight = 142;
        
    }else if ([model.cellType isEqualToString:ProblemCellTypeTContent]){
        
        NSString *str = model.questionContent;
        CGSize size = [self sizeWithLabelWithContent:str width:ScreenWidth - 20 font:[UIFont systemFontOfSize:14]];
        
        //因为这块最初设计时，只有文字，后来要加上图片 鹏飞添加
        
        if (model.attachmentList.count==0) {
            
            _cellHeight = size.height + 20;
            
        }else{
            
             _cellHeight = size.height + 100;
        }
       
        
    }else if ([model.cellType isEqualToString:ProblemCellTypeNormal]){
    
        NSString *str = model.questionContent;
        CGSize size = [self sizeWithLabelWithContent:str width:ScreenWidth - 20 font:[UIFont systemFontOfSize:14]];
        _cellHeight = size.height + 100;
    }
    else if ([model.cellType isEqualToString:ProblemCellTypeImages]){
        
        NSString *str = model.questionContent;
        CGSize size = CGSizeMake(0, 0);
        if (str.length > 0) {
            size = [self sizeWithLabelWithContent:str width:ScreenWidth - 20 font:[UIFont systemFontOfSize:14]];
        }
        
        int line;
        int listContentNum = (int)model.attachmentList.count;
        if (listContentNum % 4 == 0 ) {
            line = (int)listContentNum / 4;
        }else
            line = (int)listContentNum/4 + 1;
        
        _cellHeight = 70 * line + 50 + size.height + 10 + 20;
    }
    else if ([model.cellType isEqualToString:ProblemCellTypeAddContent]){
        NSString *str = model.questionContent;
        CGSize size = [self sizeWithLabelWithContent:str width:ScreenWidth - 20 font:[UIFont systemFontOfSize:14]];
        _cellHeight = size.height + 100 + 30 + 10;
    }
}
///根据字符串内容返回字符串的size
- (CGSize)sizeWithLabelWithContent:(NSString *)content width:(CGFloat)width font:(UIFont *)font{
    
    NSDictionary *dict=@{NSFontAttributeName : font};
    CGRect rect=[content boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dict context:nil];
    CGFloat sizeWidth=ceilf(CGRectGetWidth(rect));
    CGFloat sizeHieght=ceilf(CGRectGetHeight(rect));
    return CGSizeMake(sizeWidth, sizeHieght);
}


@end
